package com.gaohe.official.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.official.domain.FmUserCommunity;
import com.gaohe.official.service.IFmUserCommunityService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 用户圈子Controller
 *
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/userCommunity")
public class FmUserCommunityController extends BaseController
{
    @Autowired
    private IFmUserCommunityService fmUserCommunityService;

    /**
     * 查询用户圈子列表
     */
    @RequiresPermissions("official:community:list")
    @GetMapping("/list")
    public TableDataInfo list(FmUserCommunity fmUserCommunity)
    {
        startPage();
        List<FmUserCommunity> list = fmUserCommunityService.selectFmUserCommunityList(fmUserCommunity);
        return getDataTable(list);
    }

    /**
     * 导出用户圈子列表
     */
    @RequiresPermissions("official:community:export")
    @Log(title = "用户圈子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmUserCommunity fmUserCommunity)
    {
        List<FmUserCommunity> list = fmUserCommunityService.selectFmUserCommunityList(fmUserCommunity);
        ExcelUtil<FmUserCommunity> util = new ExcelUtil<FmUserCommunity>(FmUserCommunity.class);
        util.exportExcel(response, list, "用户圈子数据");
    }

    /**
     * 获取用户圈子详细信息
     */
    @RequiresPermissions("official:community:query")
    @GetMapping(value = "/{userCommunityId}")
    public AjaxResult getInfo(@PathVariable("userCommunityId") Long userCommunityId)
    {
        return success(fmUserCommunityService.selectFmUserCommunityByUserCommunityId(userCommunityId));
    }

    /**
     * 新增用户圈子
     */
    @RequiresPermissions("official:community:add")
    @Log(title = "用户圈子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmUserCommunity fmUserCommunity)
    {
        return toAjax(fmUserCommunityService.insertFmUserCommunity(fmUserCommunity));
    }

    /**
     * 修改用户圈子
     */
    @RequiresPermissions("official:community:edit")
    @Log(title = "用户圈子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmUserCommunity fmUserCommunity)
    {
        return toAjax(fmUserCommunityService.updateFmUserCommunity(fmUserCommunity));
    }

    /**
     * 删除用户圈子
     */
    @RequiresPermissions("official:community:remove")
    @Log(title = "用户圈子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userCommunityIds}")
    public AjaxResult remove(@PathVariable Long[] userCommunityIds)
    {
        return toAjax(fmUserCommunityService.deleteFmUserCommunityByUserCommunityIds(userCommunityIds));
    }
}
